﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" status="Under Construction" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Declaring modules</title>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Declaring modules</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">When developing a module in Prism, most of the time you need a base class for all the models that contain the IoC container, </text><text styleclass="Normal" style="font-style:italic;" translate="true">IRegionManager</text><text styleclass="Normal" translate="true"> and more. To make development with prism and Catel as easy as possible, the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Modules_ModuleBase" styleclass="Normal" style="font-style:normal;" translate="true">ModuleBase</link><text styleclass="Normal" style="font-style:normal;" translate="true"> is included with Catel.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-style:normal;" translate="true">There are two versions of the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Modules_ModuleBase" styleclass="Normal" style="font-style:normal;" translate="true">ModuleBase</link><text styleclass="Normal" style="font-style:normal;" translate="true"> available, which are described below.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Generic ModuleBase</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The generic module base allows the end-developer to decide what IoC container is used. For example, the developer has the choice whether the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="GEN_IoC" styleclass="Normal" translate="true">ServiceLocator</link><text styleclass="Normal" translate="true"> or any other IoC container such as Unity or MEF is used.</text></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Defining a module</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Defining a module is very simple. Just create a new class with the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Modules_ModuleBase" styleclass="Normal" style="font-style:normal;" translate="true">ModuleBase</link><text styleclass="Normal" translate="true"> as base class.</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:bold; font-style:normal; text-decoration:none; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; text-decoration:none; color:#000000;" translate="true">class</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">MyModule</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">:</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">ModuleBase&lt;IServiceLocator&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">{</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; text-decoration:none; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">MyModule()</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; &#160; &#160;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">:</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; text-decoration:none; color:#000000;" translate="true">base</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">(&quot;My module&quot;,</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">ServiceLocator.Instance.ResolveType&lt;IModuleTracker&gt;(),</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">ServiceLocator.Instance)</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">{</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; </text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">}</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; </text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; text-decoration:none; color:#000000;" translate="true">protected</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; text-decoration:none; color:#000000;" translate="true">override</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">T</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">GetService&lt;T&gt;()</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">{</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; &#160; &#160;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; text-decoration:none; color:#000000;" translate="true">return</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">Container.ResolveType&lt;T&gt;();</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#ffffff;" translate="true"> &#160; </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">}</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;" translate="true">}</text></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Handling code when the module is initialized</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The ModuleBase contains convenience methods when the module is initialized. Simple override the </text><text styleclass="Normal" style="font-style:italic;" translate="true">OnInitializing</text><text styleclass="Normal" translate="true"> or </text><text styleclass="Normal" style="font-style:italic;" translate="true">OnInitialized</text><text styleclass="Normal" translate="true"> methods.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Non-generic ModuleBase</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The non-generic base uses the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="GEN_IoC" styleclass="Normal" translate="true">ServiceLocator</link><text styleclass="Normal" translate="true"> as default IoC container. This class derives from the generic module base and specifies the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="GEN_IoC" styleclass="Normal" translate="true">ServiceLocator</link><text styleclass="Normal" translate="true"> as IoC container.</text></para>
  </body>
</topic>
